<?php
include_once( 'init.php' );

if($_GET['type'] == "favorites"){
	$timeline = $ptl["favorites"];
}
else if($_GET['search']){
	$timeline = $ptl;
}
else{
	$timeline = $ptl["statuses"];
}
for($i=0; $i<count($timeline); $i++){
	if($_GET['type'] == "favorites"){
		$thistimeline = $timeline[$i]["status"];
	}
	else{
		$thistimeline = $timeline[$i];
	}
	if(!$thistimeline["user"]["id"]){
		$thistimeline = getCache($thistimeline["id"]);
		$cachedPost = true;
	}
	else{
		$cachedPost = false;
	}
	cacheWeibo($thistimeline);
	$statePostUserHead = $thistimeline["user"]["profile_image_url"];
	$statePostUserName = $thistimeline["user"]["screen_name"];
	$statePostUserUid = $thistimeline["user"]["id"];
	$statePostUserName = $statePostUserName?$statePostUserName:$statePostUserUid;
	$statePostUserRemark =  $thistimeline["user"]["remark"];
	$statePostId = $thistimeline["id"];
	$statePostTime = $thistimeline["created_at"];
	$statePostSource = $thistimeline["source"];
	$statePostText = $thistimeline["text"];
	$statePostTextO = $statePostText;
	$statePostImage = $thistimeline["bmiddle_pic"];
	$statePostRetweet = $thistimeline["retweeted_status"];
	$statePostCommentCount = $thistimeline["comments_count"];
	if($statePostCommentCount){
		$statePostCommentList = $c->get_comments_by_sid($statePostId, 1, 1);
		$statePostComment = $statePostCommentList["comments"][0];
	}
	else{
		$statePostComment = "";
	}
	if(!$statePostUserUid){
		continue;
	}
	if($i==0 && $page==1 && $_GET['type'] != "favorites"){
?>
<div id="max_id" style="display: none;">
<?php echo $statePostId; ?>
</div>
<?php
	}
?>
<div name="statePost" id="post-<?php echo $statePostId; ?>" <?php if($cachedPost){ ?>class="statePost cachedWeibo"<?php }else{ ?>class="statePost"<?php }?>>
<div class="stateUserHead" style="background: url(<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($statePostUserHead):$statePostUserHead; ?>)">
</div>
<div class="statePostContent">
<div class="statePostTrig"></div>
<div class="statePostInfo"><span class="statePostUserName"><a href="/user/<?php echo $statePostUserName; ?>"><?php echo $statePostUserName; ?></a></span><?php if($statePostUserRemark){echo "(".$statePostUserRemark.")";} ?> - <?php if($statePostId){ ?><a href="/post/<?php echo $statePostId; ?>"><?php echo formatTime($statePostTime); ?></a><?php }else{ echo formatTime($statePostTime); } ?> - 来自<?php echo $statePostSource; ?></div><?php if($thistimeline["reposts_count"]){?><div class="repostCount">- <?php echo $thistimeline["reposts_count"]; ?></div><?php } ?><div style="clear: both"></div>
<div class="statePostWords">
<div>
<?php
echo format($statePostText);
?>

<?php if(!$statePostRetweet && $musicUrl = getMusicUrl($statePostText)){ ?>
<div id="music-<?php echo $statePostId; ?>" style="margin: 10px 0px; padding: 3px;">
<embed height="33" width="257" wmode="transparent" type="application/x-shockwave-flash" src="<?php echo $musicUrl; ?>"></embed>
</div>
<?php } ?>

<?php if($statePostImage){ ?>
<div class="statePostImageOuter"><img onclick="showImage('<?php echo $thistimeline["original_pic"]; ?>');" class="statePostImage" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($statePostImage):$statePostImage; ?>"></div>
<?php } ?>

<?php if(!$statePostRetweet && $videoUrl = getVideoUrl($statePostText)){ ?>
<div class="videoDiv">
<div id="svideo-<?php echo $statePostId; ?>" class="videoAction" onclick="showVideo('video-<?php echo $statePostId; ?>',this,'cvideo-<?php echo $statePostId; ?>');"><?php echo $videoUrl[1]; ?></div>
<div id="video-<?php echo $statePostId; ?>" style="display: none; position: relative;"><div id="cvideo-<?php echo $statePostId; ?>" class="videoClose" onclick="closeVideo('video-<?php echo $statePostId; ?>', 'svideo-<?php echo $statePostId; ?>')"><a href="javascript:void(0)">收起</a></div>
<embed src="<?php echo $videoUrl[0]; ?>" allowFullScreen="true" quality="high" width="480" height="400" wmode="transparent" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" allowNetworking="all" allowScriptAccess="always"></embed>
</div>
</div>
<?php } ?>

<?php if($statePostRetweet){ ?>
<?php
if(!$statePostRetweet["user"]["id"] && ($cache = getCache($statePostRetweet["id"]))){
	$statePostRetweet = $cache;
	$cached = true;
}
else{
	$cached = false;
	if($statePostRetweet["user"]["id"]){
		cacheWeibo($statePostRetweet);
	}
}
$statePostRetweetUserName = $statePostRetweet["user"]["screen_name"];
$statePostRetweetUserId = $statePostRetweet["user"]["id"];
$statePostRetweetUserName = $statePostRetweetUserName?$statePostRetweetUserName:$statePostRetweetUserId;
?>
<div <?php if($cached){ ?>class="stateRepost cachedWeibo"<?php }else{ ?>class="stateRepost"<?php }?>>
<?php if($statePostRetweet["user"]["id"]){ ?>
<div class="statePostInfo"><span class="statePostUserName"><a href="/user/<?php echo $statePostRetweetUserName; ?>"><?php echo $statePostRetweetUserName; ?></a></span> - <a href="/post/<?php echo $statePostRetweet["id"]; ?>"><?php echo formatTime($statePostRetweet["created_at"]); ?></a> - 来自<?php echo $statePostRetweet["source"]; ?></div><?php if($statePostRetweet["reposts_count"]){?><div class="repostCount"> - <?php echo $statePostRetweet["reposts_count"]; ?></div><?php } ?><div style="clear: both"></div>
<?php
}
$statePostText = $statePostRetweet["text"];
if($_GET['search']){
	$statePostText = strip_tags(urldecode($statePostText));
}
echo format($statePostText);
?>

<?php if($musicUrl = getMusicUrl($statePostText)){ ?>
<div id="rmusic-<?php echo $statePostId; ?>" style="margin: 10px 0px; padding: 3px;">
<embed height="33" width="257" wmode="transparent" type="application/x-shockwave-flash" src="<?php echo $musicUrl; ?>"></embed>
</div>
<?php } ?>

<?php if($statePostRetweet["bmiddle_pic"]){ ?>
<div class="statePostImageOuter"><img onclick="showImage('<?php echo $statePostRetweet["original_pic"]; ?>');" class="statePostImage" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($statePostRetweet["bmiddle_pic"]):$statePostRetweet["bmiddle_pic"]; ?>"></div>
<?php } ?>

<?php if($videoUrl = getVideoUrl($statePostText)){ ?>
<div class="videoDiv">
<div id="rsvideo-<?php echo $statePostId; ?>" class="videoAction" onclick="showVideo('rvideo-<?php echo $statePostId; ?>',this,'rcvideo-<?php echo $statePostId; ?>');"><?php echo $videoUrl[1]; ?></div>
<div id="rvideo-<?php echo $statePostId; ?>" style="display: none; position: relative;"><div id="rcvideo-<?php echo $statePostId; ?>" class="videoClose" onclick="closeVideo('rvideo-<?php echo $statePostId; ?>', 'rsvideo-<?php echo $statePostId; ?>')"><a href="javascript:void(0)">收起</a></div>
<embed src="<?php echo $videoUrl[0]; ?>" allowFullScreen="true" quality="high" width="480" height="400" wmode="transparent" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" allowNetworking="all" allowScriptAccess="always"></embed>
</div>
</div>
<?php } ?>

</div>
<?php } ?>
</div>
<?php if($statePostId){ ?>
<div id="comments-<?php echo $statePostId; ?>" class="statePostActions"><a href="#" onclick="showPublishBox('<?php echo $statePostId; ?>', '<?php echo $statePostRetweet?("//@".$statePostUserName.": ".$statePostTextO):""; ?>');return false;">转发</a> - <?php if($_GET["type"] == "favorites"){ ?><a href="##" onclick="removeFavorites('<?php echo $statePostId; ?>');return false;">取消收藏</a><? }else{ ?><a href="##" onclick="addFavorites('<?php echo $statePostId; ?>');return false;">收藏</a><? } ?> - <a href="#" onclick="if(document.getElementById('comment-<?php echo $statePostId; ?>').style.display=='block'){document.getElementById('comment-<?php echo $statePostId; ?>').style.display='none';}else{document.getElementById('comment-<?php echo $statePostId; ?>').style.display='block';document.getElementById('commentbox-<?php echo $statePostId; ?>').focus();}return false;">评论</a><?php if($statePostUserUid == $uid){ ?> - <a href="##" onclick="deletePost('<?php echo $statePostId; ?>',0);return false;">删除</a><? } ?></div>
<div <?php if($statePostComment){ ?>style="display: block;"<?php } ?> id="comment-<?php echo $statePostId; ?>" class="statePostCommentBoxDiv">
<?php
	if($statePostComment){
	$statePostCommentText = $statePostComment["text"];
	$statePostCommentText = format($statePostCommentText);
	$statePostCommentUserName = $statePostComment["user"]["screen_name"];
	$statePostCommentUserId = $statePostComment["user"]["id"];
	$statePostCommentUserName = $statePostCommentUserName?$statePostCommentUserName:$statePostCommentUserId;
?>
<div id="comment_line_<?php echo $statePostId; ?>">
<div class="statePostComment" id="comment_<?php echo $statePostComment["id"]; ?>">
<div>
<div class="statePostCommentHead"><img style="width: 30px; height: 30px;" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($statePostComment["user"]["profile_image_url"]):$statePostComment["user"]["profile_image_url"]; ?>" /></div>
<div class="statePostCommentPost">
<div><span class="statePostCommentUserName"><a href="/user/<?php echo $statePostCommentUserName; ?>"><?php echo $statePostCommentUserName; ?></a></span> - <?php echo $statePostCommentText; ?></div>
<div class="statePostCommentTime"><?php echo formatTime($statePostComment["created_at"]); ?> - <span class="commentsReplayAction"><a href="##" onclick="setElCenter(document.getElementById('replaybox-<?php echo $statePostId; ?>'));replayComment('replaybox-<?php echo $statePostId; ?>','<?php echo $statePostCommentUserName; ?>','commentid-<?php echo $statePostId; ?>','<?php echo $statePostComment["id"]; ?>');document.getElementById('commentbox-<?php echo $statePostId; ?>').focus();return false;">回复</a><?php if($statePostUserUid == $uid || $statePostComment["user"]["id"]==$uid){ ?> - <a href="##" onclick="delComment(<?php echo $statePostComment["id"]; ?>);return false;">删除</a><?php }; ?></span></div>
</div>
<div class="floatClear"></div>
</div>
</div>
</div>
<?php if($statePostCommentList["total_number"] && "10" < $statePostCommentList["total_number"]){ ?>
<div class="statePostMoreComments" style="display: none;" id="show_all_comments_<?php echo $statePostId; ?>">
后面还有<?php echo $statePostCommentList["total_number"]-10; ?>条评论，<span class="statePostMoreCommentsLink"><a href="/post/<?php echo $statePostId; ?>#comments">点击查看»</a></span>
</div>
<?php } ?>
<?php if($statePostCommentList["total_number"] && "1" != $statePostCommentList["total_number"]){ ?>
<div class="statePostMoreComments" id="show_more_comments_<?php echo $statePostId; ?>">
后面还有<?php echo $statePostCommentList["total_number"]-1; ?>条评论，<span class="statePostMoreCommentsLink"><a href="/post/<?php echo $statePostId; ?>#comments" onclick="showMoreComments('<?php echo $statePostId; ?>');return false;">点击查看»</a></span>
</div>
<?php } ?>
<?php } ?>
<div class="statePostCommentBox">
<div id="commentid-<?php echo $statePostId; ?>" style="visibility: hidden; height: 0;"></div>
<table>
<tr>
<td id="replaybox-<?php echo $statePostId; ?>" class="statePostCommentBoxReplay"></td>
<td class="statePostCommentInnerBox">
<input type="text" id="commentbox-<?php echo $statePostId; ?>" onfocus="if(this.value == '添加评论'){this.value='';this.style.color='#000000';}" onblur="if(this.value==''){this.style.color='#888888';this.value='添加评论'};" onkeydown="if(event.keyCode==13){return false;}" class="statePostCommentInnerInput" value="添加评论" />
</td>
</tr>
</table>
</div>
<div class="statePostCommentButton" onclick="replaynew('<?php echo $statePostId; ?>', document.getElementById('commentbox-<?php echo $statePostId; ?>').value, document.getElementById('commentid-<?php echo $statePostId; ?>').innerHTML, 0, 'comment-<?php echo $statePostId; ?>', 0);document.getElementById('commentbox-<?php echo $statePostId; ?>').style.color='#888888';document.getElementById('commentbox-<?php echo $statePostId; ?>').value='添加评论';document.getElementById('commentid-<?php echo $statePostId; ?>').innerHTML='';document.getElementById('replaybox-<?php echo $statePostId; ?>').style.display='none';document.getElementById('replaybox-<?php echo $statePostId; ?>').innerHTML='';">评　论</div>
<div class="floatClear"></div>
</div>
<?php } ?>
</div>
</div>
<div class="floatClear"></div>
</div>
<?php
}
?>